Skip to content

SPARC: Start moving runtime libcall config to tablegen #147672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jul 9, 2025

No description provided.

@arsenm arsenm requested review from jyknight and koachan July 9, 2025 07:49
Copy link
Contributor Author

arsenm commented Jul 9, 2025

@arsenm arsenm requested review from nikic and RKSimon July 9, 2025 07:49
@arsenm arsenm marked this pull request as ready for review July 9, 2025 07:50
@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2025

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-backend-sparc

Author: Matt Arsenault (arsenm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/147672.diff

2 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+16)
  • (modified) llvm/lib/Target/Sparc/SparcISelLowering.cpp (-13)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 403d98912653d..1554a6b7697e2 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -1828,6 +1828,22 @@ def _Q_qtoull : RuntimeLibcallImpl<FPTOUINT_F128_I64>;
 def _Q_lltoq : RuntimeLibcallImpl<SINTTOFP_I64_F128>;
 def _Q_ulltoq : RuntimeLibcallImpl<UINTTOFP_I64_F128>;
 
+def isSPARC : RuntimeLibcallPredicate<"TT.isSPARC()">;
+def isSPARC32 : RuntimeLibcallPredicate<"TT.isSPARC32()">;
+def isSPARC64 : RuntimeLibcallPredicate<"TT.isSPARC64()">;
+
+defvar SPARC64_MulDivCalls = [
+  __mulsi3, __divsi3, __modsi3, __udivsi3, __umodsi3
+];
+
+def SPARCSystemLibrary
+    : SystemRuntimeLibrary<isSPARC,
+      (add (sub DefaultLibcallImpls32, SPARC64_MulDivCalls),
+            sparc_umul, sparc_div, sparc_udiv, sparc_rem, sparc_urem,
+       LibcallImpls<(add _Q_qtoll, _Q_qtoull, _Q_lltoq, _Q_ulltoq), isSPARC32>,
+       LibcallImpls<(add SPARC64_MulDivCalls, Int128RTLibcalls), isSPARC64>)
+>;
+
 //===----------------------------------------------------------------------===//
 // Windows Runtime Libcalls
 //===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Target/Sparc/SparcISelLowering.cpp b/llvm/lib/Target/Sparc/SparcISelLowering.cpp
index 9487234561824..9b434d87c2676 100644
--- a/llvm/lib/Target/Sparc/SparcISelLowering.cpp
+++ b/llvm/lib/Target/Sparc/SparcISelLowering.cpp
@@ -1824,12 +1824,6 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
   setOperationAction(ISD::MULHS,     MVT::i32, Expand);
   setOperationAction(ISD::MUL,       MVT::i32, Expand);
 
-  setLibcallImpl(RTLIB::MUL_I32, RTLIB::sparc_umul);
-  setLibcallImpl(RTLIB::SDIV_I32, RTLIB::sparc_div);
-  setLibcallImpl(RTLIB::UDIV_I32, RTLIB::sparc_udiv);
-  setLibcallImpl(RTLIB::SREM_I32, RTLIB::sparc_rem);
-  setLibcallImpl(RTLIB::UREM_I32, RTLIB::sparc_urem);
-
   if (Subtarget->useSoftMulDiv()) {
     // .umul works for both signed and unsigned
     setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand);
@@ -1879,13 +1873,6 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
     setOperationAction(ISD::STORE, MVT::f128, Custom);
   }
 
-  if (!Subtarget->is64Bit()) {
-    setLibcallImpl(RTLIB::FPTOSINT_F128_I64, RTLIB::_Q_qtoll);
-    setLibcallImpl(RTLIB::FPTOUINT_F128_I64, RTLIB::_Q_qtoull);
-    setLibcallImpl(RTLIB::SINTTOFP_I64_F128, RTLIB::_Q_lltoq);
-    setLibcallImpl(RTLIB::UINTTOFP_I64_F128, RTLIB::_Q_ulltoq);
-  }
-
   if (Subtarget->hasHardQuad()) {
     setOperationAction(ISD::FADD,  MVT::f128, Legal);
     setOperationAction(ISD::FSUB,  MVT::f128, Legal);

@llvmbot llvmbot added the llvm:ir label Jul 9, 2025
@arsenm arsenm force-pushed the users/arsenm/sparc/start-moving-runtime-libcalls-tablegen branch from 38bfe36 to 8dfe2c8 Compare July 9, 2025 14:38
Copy link
Contributor Author

arsenm commented Jul 14, 2025

Merge activity

  • Jul 14, 9:08 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 14, 9:12 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 14, 9:16 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 14, 9:18 AM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/sparc/remove-conditions-setLibcallImpl branch from 1a0e627 to 345df81 Compare July 14, 2025 09:09
Base automatically changed from users/arsenm/sparc/remove-conditions-setLibcallImpl to main July 14, 2025 09:11
@arsenm arsenm force-pushed the users/arsenm/sparc/start-moving-runtime-libcalls-tablegen branch from 8dfe2c8 to 29bb6c9 Compare July 14, 2025 09:12
@arsenm arsenm force-pushed the users/arsenm/sparc/start-moving-runtime-libcalls-tablegen branch from 29bb6c9 to f3cf776 Compare July 14, 2025 09:15
@arsenm arsenm merged commit 51c89f3 into main Jul 14, 2025
7 of 9 checks passed
@arsenm arsenm deleted the users/arsenm/sparc/start-moving-runtime-libcalls-tablegen branch July 14, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants